import { RouteRecordRaw } from 'vue-router';
// import { setFilterHasRolesMenu } from './frontEnd';

/**
 * 建议：路由 path 路径与文件夹名称相同，找文件可浏览器地址找，方便定位文件位置
 *
 * 路由meta对象参数说明
 * meta: {
 *      title:          菜单栏及 tagsView 栏、菜单搜索名称（国际化）
 *      isLink：        是否超链接菜单，开启外链条件，`1、isLink: 链接地址不为空 2、isIframe:false`
 *      isHide：        是否隐藏此路由
 *      isKeepAlive：   是否缓存组件状态
 *      isAffix：       是否固定在 tagsView 栏上
 *      isIframe：      是否内嵌窗口，开启条件，`1、isIframe:true 2、isLink：链接地址不为空`
 *      roles：         当前路由权限标识，取角色管理。控制路由显示、隐藏。超级管理员：admin 普通角色：common
 *      icon：          菜单、tagsView 图标，阿里：加 `iconfont xxx`，fontawesome：加 `fa xxx`
 * }
 */

// 扩展 RouteMeta 接口
declare module 'vue-router' {
	interface RouteMeta {
		title?: string;
		isLink?: string;
		isHide?: boolean;
		isKeepAlive?: boolean;
		isAffix?: boolean;
		isIframe?: boolean;
		roles?: string[];
		icon?: string;
	}
}

/**
 * 定义动态路由
 * 前端添加路由，请在顶级节点的 `children 数组` 里添加
 * @description 未开启 isRequestRoutes 为 true 时使用（前端控制路由），开启时第一个顶级 children 的路由将被替换成接口请求回来的路由数据
 * @description 各字段请查看 `/@/views/system/menu/component/addMenu.vue 下的 ruleForm`
 * @returns 返回路由菜单数据
 */
export const dynamicRoutes: Array<RouteRecordRaw> = [
	{
		path: '/',
		name: 'fpage',
		component: () => import('/@/layout/index.vue'),
		redirect: '/home',
		meta: {
			isKeepAlive: true,
		},
		children: [
			{
				path: '/home',
				name: 'home',
				component: () => import('/@/views/home/index.vue'),
				meta: {
					title: 'message.router.home',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: true,
					isIframe: false,
					roles: ['SUPER_ADMIN', 'COMPANY_ADMIN', 'DEALER_ADMIN', 'BRANCH', 'common'],
					icon: 'iconfont icon-shouye',
				},
			},
			{
				path: '/org',
				name: 'org',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '',
				meta: {
					title: 'message.router.org',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['SUPER_ADMIN'],
					icon: 'iconfont icon-caidan',
				},
				children: [
					{
						path: '/org/company',
						name: 'orgCompany',
						component: () => import('/@/views/org/company/index.vue'),
						meta: {
							title: 'message.router.orgCompany',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['SUPER_ADMIN'],
							icon: 'iconfont icon-caidan',
						},
					},
					// {
					// 	path: '/org/dealer',
					// 	name: 'orgDealer',
					// 	component: () => import('/@/views/org/dealer/company/index.vue'),
					// 	meta: {
					// 		title: 'message.router.orgDealer',
					// 		isLink: '',
					// 		isHide: false,
					// 		isKeepAlive: true,
					// 		isAffix: false,
					// 		isIframe: false,
					// 		roles: ['SUPER_ADMIN', 'COMPANY'],
					// 		icon: 'iconfont icon-caidan',
					// 	},
					// },
					// {
					// 	path: '/org/branch',
					// 	name: 'orgBranch',
					// 	component: () => import('/@/views/org/branch/index.vue'),
					// 	meta: {
					// 		title: 'message.router.orgBranch',
					// 		isLink: '',
					// 		isHide: false,
					// 		isKeepAlive: true,
					// 		isAffix: false,
					// 		isIframe: false,
					// 		roles: ['SUPER_ADMIN', 'COMPANY', 'DEALER'],
					// 		icon: 'iconfont icon-caidan',
					// 	},
					// },
					// {
					// 	path: '/org/maintainer',
					// 	name: 'orgMaintainer',
					// 	component: () => import('/@/views/org/maintainer/index.vue'),
					// 	meta: {
					// 		title: 'message.router.orgMaintainer',
					// 		isLink: '',
					// 		isHide: false,
					// 		isKeepAlive: true,
					// 		isAffix: false,
					// 		isIframe: false,
					// 		roles: ['SUPER_ADMIN', 'COMPANY', 'DEALER', 'BRANCH'],
					// 		icon: 'iconfont icon-caidan',
					// 	},
					// },
				],
			},
			{
				path: '/dealer',
				name: 'dealer',
				component: () => import('/@/views/dealer/index.vue'),
				meta: {
					title: '代理商',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['SUPER_ADMIN', 'COMPANY_ADMIN',],
					icon: 'iconfont icon-caidan',
				},
			},
			{
				path: '/subdealer',
				name: 'subdealer',
				component: () => import('/@/views/dealer/index.vue'),
				meta: {
					title: 'message.router.orgSubDealer',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['DEALER_ADMIN'],
					andRoleLevel: 1,
					icon: 'iconfont icon-caidan',
				},
			},
			{
				path: '/maintainer',
				name: 'orgMaintainer',
				component: () => import('/@/views/org/maintainer/index.vue'),
				meta: {
					title: 'message.router.orgMaintainer',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['SUPER_ADMIN', 'COMPANY', 'BRANCH'],
					icon: 'iconfont icon-caidan',
				},
			},
			{
				path: '/work',
				name: 'work',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '',
				meta: {
					title: 'message.router.work',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['SUPER_ADMIN', 'COMPANY'],
					icon: 'iconfont icon-caidan',
				},
				children: [
					{
						path: '/work/apply',
						name: 'workApply',
						component: () => import('/@/views/order/index.vue'),
						meta: {
							title: 'message.router.apply',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['SUPER_ADMIN', 'COMPANY', 'DEALER', 'BRANCH'],
							icon: 'iconfont icon-caidan',
						},
					},
					{
						path: '/work/order',
						name: 'workOrder',
						component: () => import('/@/views/orderRecord/index.vue'),
						meta: {
							title: 'message.router.order',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['SUPER_ADMIN', 'COMPANY', 'DEALER', 'BRANCH'],
							icon: 'iconfont icon-caidan',
						},
					},
				],
			},
			{
				path: '/device',
				name: 'device',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '',
				meta: {
					title: 'message.router.device',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['SUPER_ADMIN', 'COMPANY_ADMIN', 'DEALER_ADMIN', 'BRANCH'],
					icon: 'iconfont icon-caidan',
				},
				children: [
					{
						path: '/device/list',
						name: 'deviceList',
						component: () => import('/@/views/device/device/index.vue'),
						meta: {
							title: 'message.router.deviceList',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['SUPER_ADMIN', 'COMPANY_ADMIN', 'DEALER_ADMIN', 'BRANCH'],
							icon: 'iconfont icon-caidan',
						},
					},
				],
			},
			// {
			// 	path: '/dict',
			// 	name: 'dict',
			// 	component: () => import('/@/layout/routerView/parent.vue'),
			// 	redirect: '',
			// 	meta: {
			// 		title: 'message.router.dict',
			// 		isLink: '',
			// 		isHide: false,
			// 		isKeepAlive: true,
			// 		isAffix: false,
			// 		isIframe: false,
			// 		roles: ['SUPER_ADMIN', 'COMPANY_ADMIN'],
			// 		icon: 'iconfont icon-caidan',
			// 	},
			// 	children: [
			// 		{
			// 			path: '/dict/equipmentMode',
			// 			name: 'equipmentMode',
			// 			component: () => import('/@/views/equipmentmode/index.vue'),
			// 			meta: {
			// 				title: 'message.router.equipmentMode',
			// 				isLink: '',
			// 				isHide: false,
			// 				isKeepAlive: true,
			// 				isAffix: false,
			// 				isIframe: false,
			// 				roles: ['SUPER_ADMIN', 'COMPANY_ADMIN'],
			// 				icon: 'iconfont icon-caidan',
			// 			},
			// 		},
			// 	],
			// },
			{
				path: '/iomanager',
				name: 'iomanager',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '/iomanager/list',
				meta: {
					title: 'message.router.personManager',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['COMPANY_ADMIN'],
					icon: 'iconfont icon-xitongshezhi',
				},
				children: [
					{
						path: '/iomanager/list',
						name: 'iomanagerList',
						component: () => import('/@/views/iomanager/index.vue'),
						meta: {
							title: 'message.router.iomanager',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['COMPANY_ADMIN'],
							icon: 'iconfont icon-caidan',
						},
					},
				],
			},
			{
				path: '/system',
				name: 'system',
				component: () => import('/@/layout/routerView/parent.vue'),
				redirect: '/system/equipmentMode',
				meta: {
					title: '系统管理',
					isLink: '',
					isHide: false,
					isKeepAlive: true,
					isAffix: false,
					isIframe: false,
					roles: ['SUPER_ADMIN', 'COMPANY_ADMIN'],
					icon: 'iconfont icon-xitongshezhi',
				},
				children: [
					{
						path: '/system/equipmentMode',
						name: '设备型号',
						component: () => import('/@/views/equipmentmode/index.vue'),
						meta: {
							title: 'message.router.equipmentMode',
							isLink: '',
							isHide: false,
							isKeepAlive: true,
							isAffix: false,
							isIframe: false,
							roles: ['SUPER_ADMIN', 'COMPANY_ADMIN'],
							icon: 'iconfont icon-caidan',
						},
					},
					// {
					// 	path: '/system/account',
					// 	name: 'systemAccount',
					// 	component: () => import('/@/views/system/account/index.vue'),
					// 	meta: {
					// 		title: 'message.router.systemAccount',
					// 		isLink: '',
					// 		isHide: false,
					// 		isKeepAlive: true,
					// 		isAffix: false,
					// 		isIframe: false,
					// 		roles: ['SUPER_ADMIN', 'COMPANY_ADMIN', 'DEALER', 'BRANCH'],
					// 		icon: 'iconfont icon-caidan',
					// 	},
					// },
					// {
					// 	path: '/system/role',
					// 	name: 'systemRole',
					// 	component: () => import('/@/views/system/role/index.vue'),
					// 	meta: {
					// 		title: 'message.router.systemRole',
					// 		isLink: '',
					// 		isHide: false,
					// 		isKeepAlive: true,
					// 		isAffix: false,
					// 		isIframe: false,
					// 		roles: ['SUPER_ADMIN', 'COMPANY_ADMIN', 'DEALER'],
					// 		icon: 'ele-ColdDrink',
					// 	},
					// },
					// {
					// 	path: '/system/userlog',
					// 	name: 'systemUseLog',
					// 	component: () => import('/@/views/system/user/index.vue'),
					// 	meta: {
					// 		title: 'message.router.systemUser',
					// 		isLink: '',
					// 		isHide: false,
					// 		isKeepAlive: true,
					// 		isAffix: false,
					// 		isIframe: false,
					// 		roles: ['SUPER_ADMIN'],
					// 		icon: 'iconfont icon-icon-',
					// 	},
					// },
				],
			},
		],
	},
];

/**
 * 定义404、401界面
 * @link 参考：https://next.router.vuejs.org/zh/guide/essentials/history-mode.html#netlify
 */
export const notFoundAndNoPower = [
	{
		path: '/401',
		name: 'noPower',
		component: () => import('/@/views/error/401.vue'),
		meta: {
			title: 'message.staticRoutes.noPower',
			isHide: true,
		},
	},
	{
		path: '/:path(.*)*',
		name: 'notFound',
		component: () => import('/@/views/error/404.vue'),
		meta: {
			title: 'message.staticRoutes.notFound',
			isHide: true,
		},
	},
];

/**
 * 定义静态路由（默认路由）
 * 此路由不要动，前端添加路由的话，请在 `dynamicRoutes 数组` 中添加
 * @description 前端控制直接改 dynamicRoutes 中的路由，后端控制不需要修改，请求接口路由数据时，会覆盖 dynamicRoutes 第一个顶级 children 的内容（全屏，不包含 layout 中的路由出口）
 * @returns 返回路由菜单数据
 */
export const staticRoutes: Array<RouteRecordRaw> = [
	{
		path: '/login',
		name: 'login',
		component: () => import('/@/views/login/index.vue'),
		meta: {
			title: '登录',
		},
	},
	/**
	 * 提示：写在这里的为全屏界面，不建议写在这里
	 * 请写在 `dynamicRoutes` 路由数组中
	 */
	{
		path: '/visualizingDemo1',
		name: 'visualizingDemo1',
		component: () => import('/@/views/visualizing/demo1.vue'),
		meta: {
			title: 'message.router.visualizingLinkDemo1',
		},
	},
	{
		path: '/visualizingDemo2',
		name: 'visualizingDemo2',
		component: () => import('/@/views/visualizing/demo2.vue'),
		meta: {
			title: 'message.router.visualizingLinkDemo2',
		},
	},
];
